
package edu.upn.sigemfi.rec.bc;

import edu.upn.sigemfi.rec.be.Notificacion;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

/**
 *
 * @author Programador
 */
public class NotificacionDelegate {
    private NotificacionFacadeLocal local;

    public NotificacionDelegate() {
        local= lookupNotificacionFacade();

    }

    private NotificacionFacadeLocal lookupNotificacionFacade() {
        try {
            Context c = new InitialContext();
            return (NotificacionFacadeLocal) c.lookup("java:comp/env/NotificacionFacade");
        } catch (NamingException ne) {
            Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
            throw new RuntimeException(ne);
        }
    }

public void crear(Notificacion Notificacion) throws Exception {
        try {
            local.create(Notificacion);
        } catch (Exception e) {
            local = lookupNotificacionFacade();
            throw new Exception("Crear Notificacion. " + e.getMessage());
        }
    }

    public void editar(Notificacion Notificacion) throws Exception {
        try {
            local.edit(Notificacion);
        } catch (Exception e) {
            local = lookupNotificacionFacade();
            throw new Exception("Editar Notificacion. " + e.getMessage());
        }
    }
    public void eliminar(Notificacion notificacion) throws Exception {
        try {
            local.remove(notificacion);
        } catch (Exception e) {
            local = lookupNotificacionFacade();
            throw new Exception("Eliminar Notificacion. " + e.getMessage());
        }
    }
    public Notificacion buscar(long codigo) throws Exception {
        try {
            return local.find(codigo);
        } catch (Exception e) {
            local = lookupNotificacionFacade();
            throw new Exception("Buscar Notificacion. " + e.getMessage());
        }
}
}